Let's learn so more about Polymorphic relationships but this one will be the Many to Many.
NOTE: There is no need to add increment ids on pivot tables unless you plan to access them directly. I include them in the video but if you want to omit them in your projects that will fine.
Summary:
We creating a Laravel Project with the database, 4 models and 4 migrations.
1. Create a new Laravel installation called polymorphicmanytomany
2 Create a database with the same name polymorphicmanytomany
3. Create 4 models, Post, Video, Tag and Taggable; here is a reminder of how we do that below
php artisan make:model Post -m
php artisan make:model Video -m
php artisan make:model Tag -m
php artisan make:model Taggable -m
4. Edit your migrations. By default we know the migrations will have $table->id(), but in the video, you might see me having the $table->increments('id'), but no worries they are almost the same thing, behind the scenes the $table->id() is $table->bigIncrements('id') behind the scenes..
The Migration create_posts_table.php of the Post model needs to have the below data.
$table->id()
$table->string('name')
$table->timestamps()5. The same thing for the migration create_videos_table.php of the Video model.
$table->id()
$table->string('name')
$table->timestamps()6. The same thing for the migration create_tags_table.php of the Tag model.
$table->id()
$table->string('name')
$table->timestamps()7. For the create_taggables_table.php migration of the Taggable model, we need this
$table->id()
$table->integer('tag_id')
$table->integer('taggable_id')
$table->string('taggable_type')
$table->timestamps()Alright, I hope you enjoy and try to keep practicing yourself with it, to see how things work.